package com.iss.lxhproject.dao;

import com.iss.lxhproject.entity.Room;
import com.iss.lxhproject.model.RoomType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Repository
@Mapper
public interface RoomfreeDao {
    @Insert("insert into roomfree values(#{room_id},#{room_type},#{room_price},#{room_state})")
     Integer insertRoom(Room room);
    @Delete(" <script>"+"delete from roomfree where room_id in" +
            "    <foreach collection=\"array\" item=\"room_id\" separator=\",\" open=\"(\" close=\")\">" +
            "        #{room_id}" +
            "    </foreach></script>")
     Integer deletRoom(String[] room_id);
    @Update("update roomfree set room_type=#{room_type},room_price=#{room_price},room_state=#{room_state} where room_id=#{room_id}")
     Integer updateRoom(Room room);
    @Select("select room_id,room_type,room_price,room_state from roomfree where room_id=#{room_id}")
     Room selectRoom(String room_id);
    @Select("<script>select * from Roomfree " +
            "<where>" +
            "<if test='priceFrom!=null'> and room_price &gt;= #{priceFrom}</if>" +
            "  <if test='priceTo!=null'> and room_price &lt;= #{priceTo}</if>"+
            "</where>" +
            "</script>")
    List<Room> selectAllRoom(Double priceFrom,Double priceTo);
    @Select("select * from roomfree where room_id=#{room_id}")
    Room selectRoomfreeById(String room_id);
    @Update("update roomfree set room_state=#{room_state} where room_id =#{room_id}" )
    Integer updateRoomState(@Param("room_state") String room_state,@Param("room_id") String room_id);

    @Select("select room_state from roomfree where room_id=#{room_id}")
    String selectRoomState(@Param("room_id")String room_id);

    @Update("<script>"+"update roomfree set room_state='空闲' where room_id in" +
            "    <foreach collection=\"array\" item=\"room_id\" separator=\",\" open=\"(\" close=\")\">" +
            "        #{room_id}" +
            "    </foreach></script>")
    Integer updateRoomState1(String[] checkout_room);
}
